package com.situ.util.dao;
import java.util.List;
import java.util.Map;

import com.situ.util.Assist;
import com.situ.util.entity.CstCustomer;
import com.situ.util.entity.CstLost;

import org.apache.ibatis.annotations.*;
/**
 * CstLost的Dao接口
 * 
 * @author 
 *
 */
@Mapper
public interface CstLostDao {

	@Select("<script> select * from cst_lost \n" +
			"<where>  lst_cust_manager_id=#{lst_cust_manager_id} " +
			"<if test=\"lst_cust_name!=null and lst_cust_name!=''\">\n " +
			" and lst_cust_name like '%${lst_cust_name}%' \n" +
			"</if> " +
			"<if test=\"lst_cust_manager_name!=null and lst_cust_manager_name!=''\">\n" +
			" and lst_cust_manager_name like '%${lst_cust_manager_name}%' </if> \n" +
			"<if test=\"lst_status!=null and lst_status!=''\">\n " +
			" and lst_status=#{lst_status} </if>" +
			"</where></script>")
	public List<CstLost> queryLostbyUid(CstLost c);

   @Select("select * from cst_lost where lst_id=#{lst_id}")
  public CstLost querylostbyLid(@Param("lst_id") Integer lst_id);

	@Select("update cst_lost set lst_delay=#{lst_delay},lst_status='1' where lst_id=#{lst_id}")
	public void  canback( CstLost c);

	@Select("update cst_lost set lst_reason=#{lst_reason},lst_lost_date=getdate(),lst_status='2' where lst_id=#{lst_id}")
	public void  cannoback(CstLost c);

    //定时器部分
	//查超过6个月无购买记录客户
	@Select(" select * from cst_customer where\n" +
			"cust_name not in(\n" +
			"\tselect odr_customer from orders\n" +
			"\t\twhere datediff(month,odr_date,getdate())<6\n" +
			") and cust_name in(select odr_customer from orders)")
	public List<CstCustomer> querycustbytime();

//根据客户id查流失表信息
	@Select(" select * from cst_lost where lst_cust_no=#{lst_cust_no}")
	public CstLost querycustbycid(@Param("lst_cust_no") String lst_cust_no);

 //添加流失信息
	@Select("insert into cst_lost(lst_cust_no,lst_cust_name,lst_cust_manager_id,lst_cust_manager_name,lst_last_order_date,lst_status) \n" +
			"values(#{lst_cust_no},#{lst_cust_name},#{lst_cust_manager_id},#{lst_cust_manager_name},#{lst_last_order_date},0)")
	public void insertlost(CstLost c);



}